var NewsViewModel = function( idTournament ){
	var self = this;
	
	self.NEWS_PER_PAGE = 5;
	
	self.page = 0;
    self.idTournament = idTournament;
	self.news = ko.observableArray( [] );
	self.isLoadingMoreNews = ko.observable( false );
	self.noMoreNews = ko.observable( false );
    
	self.init = function(){
		self.loadMoreNews();
	}
	
	self.addNew = function( n ){
		self.news.push( new New( n ) );
	}
	
	self.loadMoreNews = function(){
		self.isLoadingMoreNews( true );
		$.get( '/news/loadNews', { idTournament : self.idTournament, page : self.page }, function( data ){
			self.page++;
			self.isLoadingMoreNews( false );
			
			$( data ).each( function( index, n ){
				self.addNew( n );
			} );
			
			if( data.length < self.NEWS_PER_PAGE ) self.noMoreNews( true );
			
		} );
    }
	
	self.init();
}